package main

import (
	"fmt"

	readini "github.com/user/readini"
)

func testListen(filename string) {
	fmt.Printf("listening %v ...\n", filename)
}

func main() {
	listen := readini.ListenFunc(testListen)

	cfg, err := readini.Watch("my.ini", listen)
	if err != nil {
		fmt.Println(err)
	}

	sec, err := cfg.GetSection("")
	if err != nil {
		fmt.Println(err)
	}

	val, err := sec.GetValue("app_mode")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("App Mode: %v\n", val)

	sec, err = cfg.GetSection("paths")
	if err != nil {
		fmt.Println(err)
	}

	val, err = sec.GetValue("data")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Data Path: %v\n", val)

	sec, err = cfg.GetSection("server")
	if err != nil {
		fmt.Println(err)
	}

	val, err = sec.GetValue("protocol")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Server Protocol: %v\n", val)

	val, err = sec.GetValue("http_port")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Port Number: %v\n", val)

	val, err = sec.GetValue("enforce_domain")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("Enforce Domain: %v\n", val)

	//Not exist
	_, err = readini.Watch("notExistFile.ini", listen)
	fmt.Printf("Not exist file: %v\n", err)

	_, err = cfg.GetSection("notExistSection")
	fmt.Printf("Not exist section: %v\n", err)

	_, err = sec.GetValue("notExistKey")
	fmt.Printf("Not exist key: %v\n", err)
}
